#include "data/Player.h"
#include <QTextStream>
#include <QFile>
Player::Player(int ID, int isRed):id(ID),handCardsMax(6),crossNum(0),crossMax(2),energyMax(3),color(isRed)
{
    gem=0;
    crystal=0;
    handCardsNum=0;
}
void Player::setInfo(int roleID)
{
    QFile fp("roleDB.txt");
    QTextStream in(&fp);
    QTextStream out(stdout);
    if (!fp.open(QIODevice::ReadOnly)) {
        out << "Cannot open file for reading. ";
    }
    QString roleEntry;
    while (!in.atEnd())
    {
        roleEntry=in.readLine();
        if(roleEntry[0].digitValue()==roleID)
        {
            info=roleEntry;
            break;
        }
    }
    fp.close();
}
QString Player::getInfo()
{
    return info;
}

void Player::addStatus(int type,Card* card)
{
    Status*status=new Status(type,card);
    statusList<<status;
    emit addStatusSIG(status);
}

void Player::removeStatus(Card* card)
{
    int i;
    for(i=0;i<statusList.count();i++)
        if(statusList.at(i)->card==card)
        {
            emit removeStatusSIG(statusList.at(i));
            statusList.removeAt(i);
        }
}

bool Player::checkStatus(int type)
{
    foreach(Status* ptr,statusList)
        if(ptr->type==type)
            return 1;
    return 0;
}

void Player::setHandCardsMax(int howMany)
{
    handCardsMax=howMany;
}
void Player::setCrossNum(int howMany)
{
    crossNum=howMany;
}

void Player::setGem(int howMany)
{
    gem=howMany;
}

void Player::setCrystal(int howMany)
{
    crystal=howMany;
}

void Player::setEnergyMax(int howMany)
{
    energyMax=howMany;
}

int Player::getID()
{
    return id;
}

QString Player::getName()
{
    return name;
}

int Player::getHandCardMax()
{
    return handCardsMax;
}

int Player::getHandCardNum()
{
    return handCardsNum;
}

int Player::getCrossNum()
{
    return crossNum;
}
int Player::getCrossMax()
{
    return crossMax;
}

int Player::getGem()
{
    return gem;
}

int Player::getCrystal()
{
    return crystal;
}

int Player::getEnergy()
{
    return gem+crystal;
}

int Player::getColor()
{
    return color;
}

int Player::getEnergyMax()
{
    return energyMax;
}

